using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GTA;
using GTA.Native;

// Only works with wommen, addon or ambient. You need to get close to them.

namespace Speech
{
    public class Main : Script
    {
        private static readonly Random _randomGenerator = new Random();

        public static Ped _closestPedToPlayer { get; set; }

        public Main()
        {
            base.KeyDown += OnKeyDown;  
        }

        public static int GenerateRandomNumberInRange(int min, int max)
        {
            return _randomGenerator.Next(min, max);
        }

        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.L)
            {
                Ped[] nearbyPeds = World.GetNearbyPeds(Game.Player.Character, 10f);

                if (nearbyPeds.Length > 0)
                {
                    _closestPedToPlayer = nearbyPeds[0];

                    if (_closestPedToPlayer.Exists() && _closestPedToPlayer != Game.Player.Character && _closestPedToPlayer.IsAlive &&
                        Function.Call<int>(Hash.GET_PED_TYPE, _closestPedToPlayer) == 5) // 5 represents female civil pedestrians
                    {
                        List<string> availableVoiceNames = new List<string>
                        {
                            "S_F_Y_BAYWATCH_01_WHITE_FULL_01",
                            "s_f_y_hooker_01_white_full_01",
                            "s_f_y_hooker_01_white_full_02"
                        };

                        Function.Call(Hash.SET_AMBIENT_VOICE_NAME, _closestPedToPlayer, availableVoiceNames[GenerateRandomNumberInRange(0, availableVoiceNames.Count)]);

                        string[] availableSpeechOptions =
                        {
                            "GENERIC_HOWS_IT_GOING",
                            "CHAT_ACROSS_STREET_RESP",
                            "GENERIC_SHOCKED_MED",
                            "GENERIC_CURSE_MED",
                            "GENERIC_WHATEVER",
                            "GENERIC_THANKS",
                            "HOOKER_CHAT_SOLO",
                            "AGREE_ACROSS_STREET"
                        };

                        string selectedSpeechOption = availableSpeechOptions[_randomGenerator.Next(0, availableSpeechOptions.Length)];

                        Function.Call(Hash.PLAY_PED_AMBIENT_SPEECH_NATIVE, _closestPedToPlayer, selectedSpeechOption, "SPEECH_PARAMS_FORCE");
                    }
                }
            }
        }
    } 
}